package com.zbest.zpay.shared.process;

import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.zbest.common.lang.enums.BizCode;
import com.zbest.common.lang.exception.ZpayException;

/**
 * Created by luqingfeng on 2015/1/28.
 */
@Service("processService")
public class ProcessServiceImpl implements ProcessService {

    private static final Logger logger = LoggerFactory.getLogger(ProcessServiceImpl.class);

    @Resource
    private ProcessTemplate     processTemplate;

    /** 
     * @see com.qiangungun.market.biz.shared.process.ProcessService#execute(java.lang.String, java.util.Map)
     */
    @Override
    public ProcessResult execute(String flow, Map<String, Object> dataMap) {

        ProcessResult response = new ProcessResult();

        try {
            processTemplate.process(flow, dataMap, response);
            response.setCode(BizCode.SUCCESS);
        } catch (ZpayException e) {
            logger.error("流程执行业务异常map=" + dataMap + ",flow=" + flow, e);
            response.setCode(e.getCode());
            response.setMessage(e.getMsg());
        } catch (Exception e) {
            logger.error("流程执行未知异常map=" + dataMap + ",flow=" + flow, e);
            response.setCode(BizCode.UNKNOWN);
        }
        return response;

    }

}
